Creating Kanzi Studio window plugins

Kanzi Studio plugins extend the functionality of Kanzi Studio and run in Kanzi Studio. Use a Kanzi Studio plugin to:

You can present a Kanzi Studio plugin either in a Kanzi Studio window that contains the plugin user interface, or as a command that users can execute from the context menu and run the plugin without a user interface. This topic covers how to create Kanzi Studio window plugins. To learn how to create Kanzi Studio command plugins, see Creating Kanzi Studio command plugins.

The default UI framework for creating Kanzi Studio window plugins is WPF. However, you can use frameworks that run on HTML using WPF's web browser control, or other frameworks by embedding the content using WPF's HwndHost control that hosts a win32 window as an element into WPF content.

Kanzi Studio plugin interface is provided as .NET framework assembly. You can find it in <KanziInstallation>/Studio/Bin/PluginInterface.dll. The plugin interface provides access to data and commands in Kanzi Studio. To develop a Kanzi Studio plugin:

  1. Create the base for a Kanzi Studio plugin. See Creating the base for a Kanzi Studio window plugin.
  2. Build and run your Kanzi Studio plugin. See Building and running a Kanzi Studio plugin.
  3. Debug your Kanzi Studio plugin. See Debugging a Kanzi Studio plugin.
  4. Add functionality to your Kanzi Studio plugin. See Adding functionality to your Kanzi Studio plugin.

To find detailed information about the Kanzi Studio plugin interface see:

Creating the base for a Kanzi Studio window plugin

Kanzi Studio window plugins are plugins that you use in a Kanzi Studio window and have a user interface. For example, use the window plugins to create an editor or to visualize the content in your project.

Here you create the base for a Kanzi Studio window plugin where you then add functionality that extends the functionality of Kanzi Studio.

To create a Kanzi Studio window plugin:

  1. In Visual Studio select File > New > Project and create a Visual C# Class Library.
  2. In the Solution Explorer right-click the project name, select Add > Reference, and add references to files:
    1. Select Assemblies > Framework targeting .NET Framework and add the reference to:
      • System.ComponentModel.Composition
      • System.XAML
    2. Click Browse... and add the reference to the <KanziInstallation>/Studio/Bin/PluginInterface.dll file.
  3. In the Solution Explorer right-click the project name, select Properties:

  4. In the Solution Explorer right-click the project name, select Add > User Control and add a User Control (WPF) item.
  5. Open the UserControl1.xaml.cs file and add the using directive for the Kanzi Studio plugin interface:
    using Rightware.Kanzi.Studio.PluginInterface;
  6. Set the UserControl1 class to implement the PluginWindow interface:
    1. Change
      public partial class UserControl1 : UserControl

      to
      public partial class UserControl1 : UserControl, PluginWindow
    2. Right-click PluginWindow and select Implement Interface.
    3. Add the KanziStudio interface to the UserControl1 class. KanziStudio interface is the entry point for operating with the Kanzi Studio plugin API.
      private KanziStudio studio;
  7. In all functions replace this line with the code you want to execute:
    throw new NotImplementedException();

    Make sure that your plugin handles all its internal exceptions and does not let them reach the Kanzi Studio interface.

    For example, set the functions in the UserControl1 class:
  8. Open the Class1.cs file and add the using directive for the System.ComponentModel.Composition and the Kanzi Studio plugin interface:
    using System.ComponentModel.Composition;
    using Rightware.Kanzi.Studio.PluginInterface;
  9. Set the Class1 class to implement the PluginWindowFactory interface, which you implement in the Class1 class. Kanzi uses this class to create the plugin. Kanzi Studio first gets the factory and defines the name of the plugin, the size of the window, if the plugin has a window, and from where in Kanzi Studio users can launch the plugin.
    1. Change
      public class Class1

      to
      public class Class1 : PluginWindowFactory
    2. Right-click PluginWindowFactory and select Implement Interface.
  10. Before the definition of the class where you create the plugin, mark the factory class which implements the PluginWindowFactory interface to be the plugin content for Kanzi Studio. This way Kanzi Studio knows that the .dll is a plugin.
    [Export(typeof(PluginContent))]
  11. In all functions replace this line with the code you want to execute:
    throw new NotImplementedException();

    Make sure that your plugin handles all its internal exceptions and does not let them reach the Kanzi Studio interface.

    For example, set the functions in the Class1 class to:
  12. Build and run the plugin. See Building and running a Kanzi Studio plugin.

To further develop your Kanzi Studio plugin, see Overview of Kanzi Studio plugin interface and Kanzi Studio plugin interface API reference.

Building and running a Kanzi Studio plugin

To build and run a Kanzi Studio plugin:

  1. In Visual Studio select Build > Build Solution to build the plugin .dll.
  2. Copy the Kanzi Studio plugin .dll to the %ProgramData%\Rightware\<KanziVersion>\plugins directory.
    If the plugins directory does not exist in %ProgramData%\Rightware\<KanziVersion>, create it.

  3. Open Kanzi Studio. If Kanzi Studio is already running select File > Import > Reload Kanzi Studio Plugins to load all newly added plugins and to apply the changes made to the plugins. If the Reload Kanzi Studio Plugins menu option is not available, restart Kanzi Studio.

    Kanzi Studio loads the plugins and adds them to either the main menu or the context menus invoked from nodes and resources.
  4. In Kanzi Studio select the plugin main menu and select the plugin, or right-click a node in the Project and select the name of your plugin to run your plugin.

Debugging a Kanzi Studio plugin

To debug a Kanzi Studio plugin:

  1. In Visual Studio create and build your Kanzi Studio plugin. See Creating the base for a Kanzi Studio window plugin.
  2. In Windows Explorer create a shortcut from your Kanzi Studio plugin .dll and move the shortcut to %ProgramData%\Rightware\<KanziVersion>\plugins.
    By default Visual Studio builds the .dll of your plugin in C:\Users\<UserName>\Documents\Visual Studio 2015\Projects\<ProjectName>\<ClassLibraryName>\bin\Debug or Release directory.
  3. In Visual Studio add the break points where you want to debug your plugin.
  4. In Visual Studio select Debug > Attach to Process ..., in the Available Processes select KanziStudio.exe and click Attach.
  5. In Kanzi Studio if you have the plugin open, close it, select File > Import > Reload Kanzi Studio Plugins to apply the changes you made to the plugin, and run the plugin.

Adding functionality to your Kanzi Studio plugin

After you create the base for a Kanzi Studio window plugin, add functionality to your plugin so that it does something useful. Here you create a plugin that shows the kzb file URL of the currently selected node or resource.

To add functionality to your Kanzi Studio plugin:

  1. Create the base for your Kanzi Studio window plugin. See Creating the base for a Kanzi Studio window plugin.
  2. In Visual Studio open the Visual Studio solution of your plugin and open the class file that implements the PluginWindow interface.
    For example, open the UserControl1.xaml.cs class file.
  3. In the class that implements the PluginWindow interface add the code that your plugin executes when you interact with the plugin in the plugin window.
    For example, to create a plugin that shows the kzb file URL of the currently selected project item use:
        public partial class UserControl1 : UserControl, PluginWindow
        {
            private KanziStudio studio;
    
            public UserControl1(KanziStudio studio)
            {
                this.studio = studio;
                InitializeComponent();
                // Subscribe to the SelectionChanged event to find out when the selection of a node or a resource changes.
                studio.SelectionChanged += Studio_SelectionChanged;
                // Set the contents of the plugin window.
                Populate();
            }
    
            // When the currently selected project item changes, set the contents of the plugin window. 
            private void Studio_SelectionChanged(object sender, EventArgs e)
            {
                Populate();
            }
    
            // Set the text in the controls that show the name and kzb file URL of the currently selected project item.
            public void Populate()
            {
                var currentSelection = studio.SelectedItems.FirstOrDefault();
                this.selectionTextBlock.Text = (currentSelection != null) ? currentSelection.Name : "< no project item selected >";
                this.kzbUrlTextBox.Text = (currentSelection != null) ? currentSelection.KzbUrl : " ";
            }
    
            ...
    
            // Set the title of the plugin window.
            public string Title
            {
                get
                {
                    return "Project item kzb file URL";
                }
            }
    
            ...
    
            // Dispose of the resources used by the window.
            public void Dispose()
            {
                if (studio != null)
                {
                    this.studio.SelectionChanged -= Studio_SelectionChanged;
                }
            }
    
            ...
    
        }
  4. In Visual Studio open the XAML file that implements the layout of the window plugin and add the content you want to show in the window.
    For example, open the UserControl1.xaml file and change
        <Grid>
    
        </Grid>
    to
        <StackPanel Margin="5">        
            <Label Content="Project Item" />
            <TextBlock x:Name="selectionTextBlock" Margin="10,5" />
            <Label Content="kzb file URL" />
            <TextBox x:Name="kzbUrlTextBox" Margin="10,5" IsReadOnly="True" />
        </StackPanel>
    
  5. Build and run the plugin. See Building and running a Kanzi Studio plugin.
    Select in the Project a node or in the Library a resource. The plugin window shows the kzb file URL of the selected project item.

See also

Overview of Kanzi Studio plugin interface

Kanzi Studio plugin interface API reference

Installing Kanzi Studio plugins

Creating Kanzi Studio command plugins

Kanzi Studio plugins